package com.sh169.util;

import java.awt.Color;
import java.awt.Font;
import java.awt.image.ImageFilter;

import com.octo.captcha.component.image.backgroundgenerator.BackgroundGenerator;
import com.octo.captcha.component.image.backgroundgenerator.FunkyBackgroundGenerator;
import com.octo.captcha.component.image.color.RandomListColorGenerator;
import com.octo.captcha.component.image.deformation.ImageDeformation;
import com.octo.captcha.component.image.deformation.ImageDeformationByFilters;
import com.octo.captcha.component.image.fontgenerator.FontGenerator;
import com.octo.captcha.component.image.fontgenerator.RandomFontGenerator;
import com.octo.captcha.component.image.fontgenerator.TwistedAndShearedRandomFontGenerator;
import com.octo.captcha.component.image.textpaster.DecoratedRandomTextPaster;
import com.octo.captcha.component.image.textpaster.TextPaster;
import com.octo.captcha.component.image.textpaster.textdecorator.TextDecorator;
import com.octo.captcha.component.image.wordtoimage.DeformedComposedWordToImage;
import com.octo.captcha.component.image.wordtoimage.WordToImage;
import com.octo.captcha.component.word.wordgenerator.RandomWordGenerator;
import com.octo.captcha.component.word.wordgenerator.WordGenerator;
import com.octo.captcha.engine.image.ListImageCaptchaEngine;
import com.octo.captcha.image.gimpy.GimpyFactory;


public class VerifyCodeImageEngine extends ListImageCaptchaEngine {  
    @Override  
    protected void buildInitialFactories() {  
        int minWordLength = 4;  
        int maxWordLength = 6;  
        int fontSize = 30;  
        int imageWidth = 200;  
        int imageHeight =100;  

        //word generator  
        WordGenerator wgen = new RandomWordGenerator("abcdefghijklmnpqrstuvwxyz123456789");  
  
        //word2image components  
        TextPaster randomPaster = new DecoratedRandomTextPaster(minWordLength, maxWordLength,  
                new RandomListColorGenerator(new Color[] { Color.BLACK}), new TextDecorator[] {});  
//        BackgroundGenerator background = new FunkyBackgroundGenerator(imageWidth,imageHeight,new RandomListColorGenerator(new Color[]{Color.white,Color.lightGray,Color.gray}));
        BackgroundGenerator background = new FunkyBackgroundGenerator(imageWidth,imageHeight);
    //    BackgroundGenerator background1 = new FunkyBackgroundGenerator(width, height, colorGeneratorLeftUp, colorGeneratorLeftDown, colorGeneratorRightUp, colorGeneratorRightDown, perturbationLevel)
//        FontGenerator font = new RandomFontGenerator(fontSize, fontSize, new Font[] {  
  //              new Font("nyala", Font.BOLD, fontSize)});  
        FontGenerator font = new TwistedAndShearedRandomFontGenerator(15, 19);  
        ImageDeformation postDef = new ImageDeformationByFilters(new ImageFilter[] {});  
        ImageDeformation backDef = new ImageDeformationByFilters(new ImageFilter[] {});  
        ImageDeformation textDef = new ImageDeformationByFilters(new ImageFilter[] {});  
  
        WordToImage word2image = new DeformedComposedWordToImage(font, background, randomPaster, backDef, textDef,  
                postDef);  
        addFactory(new GimpyFactory(wgen, word2image));  
    }  
}  
